﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Data.SqlClient;
using Adex;
using System.Web.UI.WebControls;


namespace MediaMonitor.Common
{

    /// <summary>
    /// Summary description for ReportFuncs
    /// </summary>
    public class ReportFuncs
    {

        #region Report - Meltimedia

        public DataTable GetReportAll_Paged(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string advertiserName, string brandName, string productName, string agencyName, int sPrice, int ePrice, bool fa, int MediaTypeCode, bool searchIN,string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            sectorName = sectorName != null ? sectorName : "";
            subSectorName = subSectorName != null ? subSectorName : "";
            categoryName = categoryName != null ? categoryName : "";
            advertiserName = advertiserName != null ? advertiserName : "";
            brandName = brandName != null ? brandName : "";
            productName = productName != null ? productName : "";
            agencyName = agencyName != null ? agencyName : "";
            days = days != null ? days : "";
            DataTable dt = SPs.GetReportAllPaged(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), searchTV, searchRD, searchCB, searchPR, searchOD, mediaCodes, sectorName, subSectorName, categoryName, advertiserName, brandName, productName, agencyName, sPrice, ePrice, fa, MediaTypeCode, searchIN,days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }
        public int GetReportAll_RowCount(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string advertiserName, string brandName, string productName, string agencyName, int sPrice, int ePrice, bool fa, int MediaTypeCode, bool searchIN,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }

        public DataTable GetReportAll_PagedExport(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string advertiserName, string brandName, string productName, string agencyName, int sPrice, int ePrice, bool fa, int MediaTypeCode, bool searchIN,string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            sectorName = sectorName != null ? sectorName : "";
            subSectorName = subSectorName != null ? subSectorName : "";
            categoryName = categoryName != null ? categoryName : "";
            advertiserName = advertiserName != null ? advertiserName : "";
            brandName = brandName != null ? brandName : "";
            productName = productName != null ? productName : "";
            agencyName = agencyName != null ? agencyName : "";
            days = days != null ? days : "";
            DataTable dt = SPs.GetReportAllPagedExport(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), searchTV, searchRD, searchCB, searchPR, searchOD, mediaCodes, sectorName, subSectorName, categoryName, advertiserName, brandName, productName, agencyName, sPrice, ePrice, fa, MediaTypeCode, searchIN, days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }
        public int GetReportAll_RowCountExport(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string advertiserName, string brandName, string productName, string agencyName, int sPrice, int ePrice, bool fa, int MediaTypeCode, bool searchIN,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }



        public DataTable GetReportAll_Count(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string advertiserName, string brandName, string productName, string agencyName, int sPrice, int ePrice, bool fa, bool searchIN,string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            sectorName = sectorName != null ? sectorName : "";
            subSectorName = subSectorName != null ? subSectorName : "";
            categoryName = categoryName != null ? categoryName : "";
            advertiserName = advertiserName != null ? advertiserName : "";
            brandName = brandName != null ? brandName : "";
            productName = productName != null ? productName : "";
            agencyName = agencyName != null ? agencyName : "";
            days = days != null ? days : "";
            //userID, page, , , sDate, eDate.AddDays(0),    ""
            
           // SPs.GetReportAll_Count(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), searchTV, searchRD, searchCB, searchPR, searchOD, searchIN, mediaCodes, sectorName, subSectorName, categoryName, advertiserName, brandName, productName, agencyName, sPrice, ePrice, fa, days).CommandTimeout = 0;
            DataTable dt = SPs.GetReportAll_Count(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), searchTV, searchRD, searchCB, searchPR, searchOD, searchIN, mediaCodes, sectorName, subSectorName, categoryName, advertiserName, brandName, productName, agencyName, sPrice, ePrice, fa, days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["CountRecord"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }
        public int GetReportAll_RowCountTotal(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string advertiserName, string brandName, string productName, string agencyName, int sPrice, int ePrice, bool fa, bool searchIN,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }





        #endregion

        #region TVCR

        public DataTable GetReportTimeBand_Paged(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int programCode, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sTime, int eTime, int sDuration, int eDuration, int posInBreak, int sPrice, int ePrice, bool fa, string days, string StartTimeBand, string EndTimeBand, string TimeBand1, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            categoryCode = categoryCode != null ? categoryCode : "";
            productCode = productCode != null ? productCode : "";
            days = days != null ? days : "";
            DataTable dt1 = SPs.GetReportCommercialPaged1(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), mediaTypeCode, mediaCodes, programCode, sectorCode, subSectorCode, subSector2Code, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sTime, eTime, sDuration, eDuration, posInBreak, sPrice, ePrice, fa, days).GetDataSet().Tables[0];
            DataView dv1 = new DataView(dt1);
            HttpContext.Current.Session["dv1"] = dv1;
            string[] sTimeBand = StartTimeBand.Split(',');
            string[] eTimeBand = EndTimeBand.Split(',');
            string[] split = TimeBand1.Split(',');
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[63] { new DataColumn("CommercialLogID", typeof(int)), 
                             new DataColumn("RFDate", typeof(string)), 
                             new DataColumn("ProdVersionID",typeof(int)),
                             new DataColumn("ProductID",typeof(int)),
                             new DataColumn("Price",typeof(string)),
                             new DataColumn("CategoryID",typeof(string)),
                             new DataColumn("BrandID",typeof(string)),
                             new DataColumn("CountryID",typeof(string)),
                             new DataColumn("MediaCode",typeof(string)),
                             new DataColumn("TypeOfBuyCode",typeof(string)),
                             new DataColumn("AgencyID",typeof(string)),
                             new DataColumn("AdvertiserID",typeof(string)),
                             new DataColumn("ProgramCode",typeof(string)),
                             new DataColumn("SectorID",typeof(string)),
                             new DataColumn("SubSectorID",typeof(string)),
                             new DataColumn("MediaTypeCode",typeof(string)),
                             new DataColumn("MediaTypeName",typeof(string)),
                             new DataColumn("MediaName",typeof(string)),
                             new DataColumn("AdvertiserName",typeof(string)),
                             new DataColumn("ProductName",typeof(string)),
                             new DataColumn("TimeStartFormatted",typeof(string)),
                             new DataColumn("Duration",typeof(string)),
                             new DataColumn("RealCost",typeof(string)),
                             new DataColumn("ShortVideo",typeof(string)),
                             new DataColumn("RadioFile",typeof(string)),
                             new DataColumn("CableFile",typeof(string)),
                             new DataColumn("ProdVersionCode",typeof(string)),
                             new DataColumn("ShortVideoFile",typeof(string)),
                             new DataColumn("AgencyName",typeof(string)),
                             new DataColumn("BrandName",typeof(string)),
                             new DataColumn("ProdVersionName",typeof(string)),
                             new DataColumn("ProgramName",typeof(string)),
                             new DataColumn("SectorName",typeof(string)),
                             new DataColumn("SubSectorName",typeof(string)),
                             new DataColumn("CategoryName",typeof(string)),
                             new DataColumn("TimeEndFormatted",typeof(string)),
                             new DataColumn("PositionInBreak",typeof(string)),
                             new DataColumn("TimeStart",typeof(string)),
                             new DataColumn("TimeEnd",typeof(string)),
                             new DataColumn("Typology",typeof(string)),
                             new DataColumn("NominalCost",typeof(string)),
                             new DataColumn("EquivalentCost",typeof(string)),
                             new DataColumn("NumberOfSpotsInBreak",typeof(string)),
                             new DataColumn("TypeOfSpot",typeof(string)),
                             new DataColumn("SubSector2ID",typeof(string)),
                             new DataColumn("DateAdded",typeof(string)),
                             new DataColumn("DateModified",typeof(string)),
                             new DataColumn("AdvertiserCode",typeof(string)),
                             new DataColumn("ProductCode",typeof(string)),
                             new DataColumn("TypeOfBuyName",typeof(string)),
                             new DataColumn("AgencyCode",typeof(string)),
                             new DataColumn("SectorCode",typeof(string)),
                             new DataColumn("SubSectorCode",typeof(string)),
                             new DataColumn("BrandCode",typeof(string)),
                             new DataColumn("CategoryCode",typeof(string)),
                             new DataColumn("FullVideo",typeof(string)),
                             new DataColumn("FullVideoFile",typeof(string)),
                             new DataColumn("PressFile",typeof(string)),
                             new DataColumn("OutDoorFile",typeof(string)),
                             new DataColumn("RowNum",typeof(string)),
                             new DataColumn("TotalRecords",typeof(string)),new DataColumn("TimeBand",typeof(string)),new DataColumn("Split",typeof(string))});
            for (int i = 0; i < sTimeBand.Length; i++)
            {
                DataView dv = (DataView)(HttpContext.Current.Session["dv1"]);
                switch (Convert.ToInt32(split[i]))
                {
                    case 0:
                        var startTime5 = DateTime.Parse(Utility.GetTimeFromNumbers(Utility.IsNullStr(sTimeBand[i].ToString(), "000000")));
                        var endTime5 = DateTime.Parse(Utility.GetTimeFromNumbers(Utility.IsNullStr(eTimeBand[i].ToString(), "000000")));
                        dv = (DataView)(HttpContext.Current.Session["dv1"]);
                        int intStartTime4 = Convert.ToInt32(startTime5.ToString("HH:mm:ss").TrimStart('0').Replace(":", ""));
                        int intEndTime4 = Convert.ToInt32(endTime5.ToString("HH:mm:ss").TrimStart('0').Replace(":", ""));
                        dv.RowFilter = "TimeStart>='" + intStartTime4 + "' and TimeEnd <='" + intEndTime4 + "'";
                        foreach (DataRowView rowView in dv)
                        {
                            dt.Rows.Add(rowView["CommercialLogID"], rowView["RFDate"], rowView["ProdVersionID"], rowView["ProductID"], rowView["Price"], rowView["CategoryID"]
                                , rowView["BrandID"], rowView["CountryID"], rowView["MediaCode"], rowView["TypeOfBuyCode"], rowView["AgencyID"], rowView["AdvertiserID"]
                                , rowView["ProgramCode"], rowView["SectorID"], rowView["SubSectorID"], rowView["MediaTypeCode"], rowView["MediaTypeName"], rowView["MediaName"]
                                , rowView["AdvertiserName"], rowView["ProductName"], rowView["TimeStartFormatted"], rowView["Duration"], rowView["RealCost"], rowView["ShortVideo"]
                                , rowView["RadioFile"], rowView["CableFile"], rowView["ProdVersionCode"], rowView["ShortVideoFile"], rowView["AgencyName"], rowView["BrandName"]
                                , rowView["ProdVersionName"], rowView["ProgramName"], rowView["SectorName"], rowView["SubSectorName"], rowView["CategoryName"], rowView["TimeEndFormatted"]
                                , rowView["PositionInBreak"], rowView["TimeStart"], rowView["TimeEnd"], rowView["Typology"], rowView["NominalCost"], rowView["EquivalentCost"]
                                , rowView["NumberOfSpotsInBreak"], rowView["TypeOfSpot"], rowView["SubSector2ID"], rowView["DateAdded"], rowView["DateModified"], rowView["AdvertiserCode"]
                                , rowView["ProductCode"], rowView["TypeOfBuyName"], rowView["AgencyCode"], rowView["SectorCode"], rowView["SubSectorCode"], rowView["BrandCode"]
                                , rowView["CategoryCode"], rowView["FullVideo"], rowView["FullVideoFile"], rowView["PressFile"], rowView["OutDoorFile"], rowView["RowNum"], rowView["TotalRecords"], startTime5.ToString("HH:mm:ss").TrimStart('0') + "-" + endTime5.ToString("HH:mm:ss").TrimStart('0'), "00:00:00");
                            // Do something //
                        }
                        break;
                    case 1:
                        var startTime = DateTime.Parse(Utility.GetTimeFromNumbers(Utility.IsNullStr(sTimeBand[i].ToString(), "000000")));
                        var endTime = DateTime.Parse(Utility.GetTimeFromNumbers(Utility.IsNullStr(eTimeBand[i].ToString(), "000000")));
                        while (startTime <= endTime)
                        {
                            dv = (DataView)(HttpContext.Current.Session["dv1"]);
                            int intStartTime = Convert.ToInt32(startTime.ToString("HH:mm:ss").TrimStart('0').Replace(":", ""));
                            int intEndTime = Convert.ToInt32(startTime.AddMinutes(1).ToString("HH:mm:ss").TrimStart('0').Replace(":", ""));
                            dv.RowFilter = "TimeStart>='" + intStartTime + "' and TimeEnd <='" + intEndTime + "'";

                            foreach (DataRowView rowView in dv)
                            {
                                dt.Rows.Add(rowView["CommercialLogID"], rowView["RFDate"], rowView["ProdVersionID"], rowView["ProductID"], rowView["Price"], rowView["CategoryID"]
                                    , rowView["BrandID"], rowView["CountryID"], rowView["MediaCode"], rowView["TypeOfBuyCode"], rowView["AgencyID"], rowView["AdvertiserID"]
                                    , rowView["ProgramCode"], rowView["SectorID"], rowView["SubSectorID"], rowView["MediaTypeCode"], rowView["MediaTypeName"], rowView["MediaName"]
                                    , rowView["AdvertiserName"], rowView["ProductName"], rowView["TimeStartFormatted"], rowView["Duration"], rowView["RealCost"], rowView["ShortVideo"]
                                    , rowView["RadioFile"], rowView["CableFile"], rowView["ProdVersionCode"], rowView["ShortVideoFile"], rowView["AgencyName"], rowView["BrandName"]
                                    , rowView["ProdVersionName"], rowView["ProgramName"], rowView["SectorName"], rowView["SubSectorName"], rowView["CategoryName"], rowView["TimeEndFormatted"]
                                    , rowView["PositionInBreak"], rowView["TimeStart"], rowView["TimeEnd"], rowView["Typology"], rowView["NominalCost"], rowView["EquivalentCost"]
                                    , rowView["NumberOfSpotsInBreak"], rowView["TypeOfSpot"], rowView["SubSector2ID"], rowView["DateAdded"], rowView["DateModified"], rowView["AdvertiserCode"]
                                    , rowView["ProductCode"], rowView["TypeOfBuyName"], rowView["AgencyCode"], rowView["SectorCode"], rowView["SubSectorCode"], rowView["BrandCode"]
                                    , rowView["CategoryCode"], rowView["FullVideo"], rowView["FullVideoFile"], rowView["PressFile"], rowView["OutDoorFile"], rowView["RowNum"], rowView["TotalRecords"], startTime.ToString("HH:mm:ss").TrimStart('0') + "-" + startTime.AddMinutes(1).ToString("HH:mm:ss").TrimStart('0'), "00:01:00");
                                // Do something //
                            }
                            startTime = startTime.AddMinutes(1);
                        }
                        break;
                    case 2:
                        var startTime2 = DateTime.Parse(Utility.GetTimeFromNumbers(Utility.IsNullStr(sTimeBand[i].ToString(), "000000")));
                        var endTime2 = DateTime.Parse(Utility.GetTimeFromNumbers(Utility.IsNullStr(eTimeBand[i].ToString(), "000000")));
                        while (startTime2 < endTime2)
                        {
                            dv = (DataView)(HttpContext.Current.Session["dv1"]);
                            int intStartTime = Convert.ToInt32(startTime2.ToString("HH:mm:ss").TrimStart('0').Replace(":", ""));
                            int intEndTime = Convert.ToInt32(startTime2.AddMinutes(15).ToString("HH:mm:ss").TrimStart('0').Replace(":", ""));
                            dv.RowFilter = "TimeStart>='" + intStartTime + "' and TimeEnd <='" + intEndTime + "'";


                            foreach (DataRowView rowView in dv)
                            {
                                dt.Rows.Add(rowView["CommercialLogID"], rowView["RFDate"], rowView["ProdVersionID"], rowView["ProductID"], rowView["Price"], rowView["CategoryID"]
                                    , rowView["BrandID"], rowView["CountryID"], rowView["MediaCode"], rowView["TypeOfBuyCode"], rowView["AgencyID"], rowView["AdvertiserID"]
                                    , rowView["ProgramCode"], rowView["SectorID"], rowView["SubSectorID"], rowView["MediaTypeCode"], rowView["MediaTypeName"], rowView["MediaName"]
                                    , rowView["AdvertiserName"], rowView["ProductName"], rowView["TimeStartFormatted"], rowView["Duration"], rowView["RealCost"], rowView["ShortVideo"]
                                    , rowView["RadioFile"], rowView["CableFile"], rowView["ProdVersionCode"], rowView["ShortVideoFile"], rowView["AgencyName"], rowView["BrandName"]
                                    , rowView["ProdVersionName"], rowView["ProgramName"], rowView["SectorName"], rowView["SubSectorName"], rowView["CategoryName"], rowView["TimeEndFormatted"]
                                    , rowView["PositionInBreak"], rowView["TimeStart"], rowView["TimeEnd"], rowView["Typology"], rowView["NominalCost"], rowView["EquivalentCost"]
                                    , rowView["NumberOfSpotsInBreak"], rowView["TypeOfSpot"], rowView["SubSector2ID"], rowView["DateAdded"], rowView["DateModified"], rowView["AdvertiserCode"]
                                    , rowView["ProductCode"], rowView["TypeOfBuyName"], rowView["AgencyCode"], rowView["SectorCode"], rowView["SubSectorCode"], rowView["BrandCode"]
                                    , rowView["CategoryCode"], rowView["FullVideo"], rowView["FullVideoFile"], rowView["PressFile"], rowView["OutDoorFile"], rowView["RowNum"], rowView["TotalRecords"], startTime2.ToString("HH:mm:ss").TrimStart('0') + "-" + startTime2.AddMinutes(15).ToString("HH:mm:ss").TrimStart('0'), "00:15:00");
                                // Do something //
                            }
                            startTime2 = startTime2.AddMinutes(15);
                        }
                        break;
                    case 3:
                        var startTime3 = DateTime.Parse(Utility.GetTimeFromNumbers(Utility.IsNullStr(sTimeBand[i].ToString(), "000000")));
                        var endTime3 = DateTime.Parse(Utility.GetTimeFromNumbers(Utility.IsNullStr(eTimeBand[i].ToString(), "000000")));
                        while (startTime3 < endTime3)
                        {
                            dv = (DataView)(HttpContext.Current.Session["dv1"]);
                            int intStartTime1 = Convert.ToInt32(startTime3.ToString("HH:mm:ss").TrimStart('0').Replace(":", ""));
                            int intEndTime1 = Convert.ToInt32(startTime3.AddMinutes(30).ToString("HH:mm:ss").TrimStart('0').Replace(":", ""));
                            dv.RowFilter = "TimeStart>='" + intStartTime1 + "' and TimeEnd <='" + intEndTime1 + "'";

                            foreach (DataRowView rowView in dv)
                            {
                                dt.Rows.Add(rowView["CommercialLogID"], rowView["RFDate"], rowView["ProdVersionID"], rowView["ProductID"], rowView["Price"], rowView["CategoryID"]
                                    , rowView["BrandID"], rowView["CountryID"], rowView["MediaCode"], rowView["TypeOfBuyCode"], rowView["AgencyID"], rowView["AdvertiserID"]
                                    , rowView["ProgramCode"], rowView["SectorID"], rowView["SubSectorID"], rowView["MediaTypeCode"], rowView["MediaTypeName"], rowView["MediaName"]
                                    , rowView["AdvertiserName"], rowView["ProductName"], rowView["TimeStartFormatted"], rowView["Duration"], rowView["RealCost"], rowView["ShortVideo"]
                                    , rowView["RadioFile"], rowView["CableFile"], rowView["ProdVersionCode"], rowView["ShortVideoFile"], rowView["AgencyName"], rowView["BrandName"]
                                    , rowView["ProdVersionName"], rowView["ProgramName"], rowView["SectorName"], rowView["SubSectorName"], rowView["CategoryName"], rowView["TimeEndFormatted"]
                                    , rowView["PositionInBreak"], rowView["TimeStart"], rowView["TimeEnd"], rowView["Typology"], rowView["NominalCost"], rowView["EquivalentCost"]
                                    , rowView["NumberOfSpotsInBreak"], rowView["TypeOfSpot"], rowView["SubSector2ID"], rowView["DateAdded"], rowView["DateModified"], rowView["AdvertiserCode"]
                                    , rowView["ProductCode"], rowView["TypeOfBuyName"], rowView["AgencyCode"], rowView["SectorCode"], rowView["SubSectorCode"], rowView["BrandCode"]
                                    , rowView["CategoryCode"], rowView["FullVideo"], rowView["FullVideoFile"], rowView["PressFile"], rowView["OutDoorFile"], rowView["RowNum"], rowView["TotalRecords"], startTime3.ToString("HH:mm:ss").TrimStart('0') + "-" + startTime3.AddMinutes(30).ToString("HH:mm:ss").TrimStart('0'), "00:30:00");
                                // Do something //
                            }
                            startTime3 = startTime3.AddMinutes(30);
                        }
                        break;
                    case 4:
                        var startTime4 = DateTime.Parse(Utility.GetTimeFromNumbers(Utility.IsNullStr(sTimeBand[i].ToString(), "000000")));
                        var endTime4 = DateTime.Parse(Utility.GetTimeFromNumbers(Utility.IsNullStr(eTimeBand[i].ToString(), "000000")));
                        while (startTime4 < endTime4)
                        {
                            dv = (DataView)(HttpContext.Current.Session["dv1"]);
                            int intStartTime1 = Convert.ToInt32(startTime4.ToString("HH:mm:ss").TrimStart('0').Replace(":", ""));
                            int intEndTime1 = Convert.ToInt32(startTime4.AddMinutes(60).ToString("HH:mm:ss").TrimStart('0').Replace(":", ""));
                            dv.RowFilter = "TimeStart>='" + intStartTime1 + "' and TimeEnd <='" + intEndTime1 + "'";

                            foreach (DataRowView rowView in dv)
                            {
                                dt.Rows.Add(rowView["CommercialLogID"], rowView["RFDate"], rowView["ProdVersionID"], rowView["ProductID"], rowView["Price"], rowView["CategoryID"]
                                    , rowView["BrandID"], rowView["CountryID"], rowView["MediaCode"], rowView["TypeOfBuyCode"], rowView["AgencyID"], rowView["AdvertiserID"]
                                    , rowView["ProgramCode"], rowView["SectorID"], rowView["SubSectorID"], rowView["MediaTypeCode"], rowView["MediaTypeName"], rowView["MediaName"]
                                    , rowView["AdvertiserName"], rowView["ProductName"], rowView["TimeStartFormatted"], rowView["Duration"], rowView["RealCost"], rowView["ShortVideo"]
                                    , rowView["RadioFile"], rowView["CableFile"], rowView["ProdVersionCode"], rowView["ShortVideoFile"], rowView["AgencyName"], rowView["BrandName"]
                                    , rowView["ProdVersionName"], rowView["ProgramName"], rowView["SectorName"], rowView["SubSectorName"], rowView["CategoryName"], rowView["TimeEndFormatted"]
                                    , rowView["PositionInBreak"], rowView["TimeStart"], rowView["TimeEnd"], rowView["Typology"], rowView["NominalCost"], rowView["EquivalentCost"]
                                    , rowView["NumberOfSpotsInBreak"], rowView["TypeOfSpot"], rowView["SubSector2ID"], rowView["DateAdded"], rowView["DateModified"], rowView["AdvertiserCode"]
                                    , rowView["ProductCode"], rowView["TypeOfBuyName"], rowView["AgencyCode"], rowView["SectorCode"], rowView["SubSectorCode"], rowView["BrandCode"]
                                    , rowView["CategoryCode"], rowView["FullVideo"], rowView["FullVideoFile"], rowView["PressFile"], rowView["OutDoorFile"], rowView["RowNum"], rowView["TotalRecords"], startTime4.ToString("HH:mm:ss").TrimStart('0') + "-" + startTime4.AddMinutes(60).ToString("HH:mm:ss").TrimStart('0'), "00:60:00");
                                // Do something //
                            }
                            startTime4 = startTime4.AddMinutes(60);
                        }
                        break;
                }

            }

            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportTVCR_RowCount(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int programCode, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sTime, int eTime, int sDuration, int eDuration, int posInBreak, int sPrice, int ePrice, bool fa,string days, string StartTimeBand, string EndTimeBand, string TimeBand1, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        public DataTable GetReportTVCR_Export(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int programCode, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sTime, int eTime, int sDuration, int eDuration, int posInBreak, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            categoryCode = categoryCode != null ? categoryCode : "";
            productCode = productCode != null ? productCode : "";
            days = days != null ? days : "";
            DataTable dt = SPs.GetReportCommercialExport(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), mediaTypeCode, mediaCodes, programCode, sectorCode, subSectorCode, subSector2Code, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sTime, eTime, sDuration, eDuration, posInBreak, sPrice, ePrice, fa,days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportTVCR_RowCountExport(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int programCode, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sTime, int eTime, int sDuration, int eDuration, int posInBreak, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        public DataTable GetReportTVCR_Count(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int programCode, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sTime, int eTime, int sDuration, int eDuration, int posInBreak, int sPrice, int ePrice, bool fa, string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            categoryCode = categoryCode != null ? categoryCode : "";
            productCode = productCode != null ? productCode : "";
            days = days != null ? days : "";
            DataTable dt = SPs.GetReportCommercialCount(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), mediaTypeCode, mediaCodes, programCode, sectorCode, subSectorCode, subSector2Code, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sTime, eTime, sDuration, eDuration, posInBreak, sPrice, ePrice, fa, days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["CountRecord"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportTVCR_RowCountTotal(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int programCode, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sTime, int eTime, int sDuration, int eDuration, int posInBreak, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        #endregion


        #region PRESS

        public DataTable GetReportPress_Paged(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            categoryCode = categoryCode != null ? categoryCode : "";
            productCode = productCode != null ? productCode : "";
            days = days != null ? days : "";
            DataTable dt = SPs.GetReportPressPaged(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), mediaTypeCode, mediaCodes, sectorCode, subSectorCode, subSector2Code, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sPrice, ePrice, fa, days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportPress_RowCount(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        public DataTable GetReportPress_Export(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            categoryCode = categoryCode != null ? categoryCode : "";
            productCode = productCode != null ? productCode : "";
            days = days != null ? days : "";
            DataTable dt = SPs.GetReportPressPagedExport(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), mediaTypeCode, mediaCodes, sectorCode, subSectorCode, subSector2Code, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sPrice, ePrice, fa, days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportPress_RowCountExport(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        public DataTable GetReportPress_Count(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            categoryCode = categoryCode != null ? categoryCode : "";
            productCode = productCode != null ? productCode : "";
            days = days != null ? days : "";
            DataTable dt = SPs.GetReportPressCount(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), mediaTypeCode, mediaCodes, sectorCode, subSectorCode, subSector2Code, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sPrice, ePrice, fa, days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["CountRecord"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportPress_RowCountTotal(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }

        #endregion


        #region OUTDOOR

        public DataTable GetReportOutdoor_Paged(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, int size, string quality, int typeOfAds, bool fa, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            quality = quality != null ? quality : "";


            DataTable dt = SPs.GetReportOutDoorPaged(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(1), mediaTypeCode, mediaCodes, sectorCode, subSectorCode, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sPrice, ePrice, size, quality, typeOfAds, fa).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportOutdoor_RowCount(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, int size, string quality, int typeOfAds, bool fa, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        public DataTable GetReportOutdoor_Export(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, int size, string quality, int typeOfAds, bool fa, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            quality = quality != null ? quality : "";


            DataTable dt = SPs.GetReportOutDoorPagedExport(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(1), mediaTypeCode, mediaCodes, sectorCode, subSectorCode, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sPrice, ePrice, size, quality, typeOfAds, fa).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportOutdoor_RowCountExport(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, int size, string quality, int typeOfAds, bool fa, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        public DataTable GetReportOutdoor_Count(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, int size, string quality, int typeOfAds, bool fa, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            quality = quality != null ? quality : "";


            DataTable dt = SPs.GetReportOutDoorCount(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(1), mediaTypeCode, mediaCodes, sectorCode, subSectorCode, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sPrice, ePrice, size, quality, typeOfAds, fa).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["CountRecord"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportOutdoor_RowCountTotal(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, int size, string quality, int typeOfAds, bool fa, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        #endregion


        #region NEWS

        public DataSet GetReportNews_PDF(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, string  categoryCode, int advertiserCode, string productCode, int sPrice, int ePrice, int sectionCode, int newsTypeCode, string newsMediaType, bool fa,string days)
        {

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            newsMediaType = newsMediaType != null ? newsMediaType : "";
            

            //DataSet ds = SPs.GetReportNewsPdf (userID, sDate, eDate.AddDays(1), mediaTypeCode, mediaCodes, newsMediaType, newsTypeCode, sectionCode, sectorCode, subSectorCode, categoryCode, advertiserCode, productCode, sPrice, ePrice, fa).GetDataSet();
            DataSet ds = SPs.GetReportNewsPdf(userID, sDate, eDate, mediaTypeCode, mediaCodes, newsMediaType, newsTypeCode, sectionCode, sectorCode, subSectorCode, categoryCode, advertiserCode, productCode, sPrice, ePrice, fa,days).GetDataSet();
            return ds;
        }

        public DataTable GetReportNews(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, string categoryCode, int advertiserCode, string productCode, int sPrice, int ePrice, int sectionCode, int newsTypeCode, string newsMediaType, bool fa,string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            newsMediaType = newsMediaType != null ? newsMediaType : "";
            categoryCode = categoryCode != null ? categoryCode : "";
            productCode = productCode != null ? productCode : "";
            days = days != null ? days : "";

            DataTable dt = SPs.GetReportNewsPaged(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(1), mediaTypeCode, mediaCodes, newsMediaType, newsTypeCode, sectionCode, sectorCode, subSectorCode, categoryCode, advertiserCode, productCode, sPrice, ePrice, fa, days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportNews_RowCount(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int categoryCode, int advertiserCode, int productCode, int sPrice, int ePrice, int sectionCode, int newsTypeCode, string newsMediaType, bool fa,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        #endregion


        #region[New Commercial]
        public DataSet GetReportCommercialPdf(int CompanyCode, DateTime sDate, DateTime eDate)
        {

            DataSet ds = SPs.GetReportCommercialPdf(CompanyCode, sDate, eDate).GetDataSet();
            return ds;
        }

        #endregion


        #region INTERNET

        public DataTable GetReportInternet_Paged(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            categoryCode = categoryCode != null ? categoryCode : "";
            productCode = productCode != null ? productCode : "";
            days = days != null ? days : "";
            DataTable dt = SPs.GetReportInternetPaged(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), mediaTypeCode, mediaCodes, sectorCode, subSectorCode, subSector2Code, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sPrice, ePrice, fa, days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportInternet_RowCount(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }

        public DataTable GetReportInternet_Count(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            days = days != null ? days : "";
            categoryCode = categoryCode != null ? categoryCode : "";
            productCode = productCode != null ? productCode : "";
            DataTable dt = SPs.GetReportInternetCount(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), mediaTypeCode, mediaCodes, sectorCode, subSectorCode, subSector2Code, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sPrice, ePrice, fa, days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["CountRecord"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportInternet_RowCountTotal(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }

        public DataTable GetReportInternet_Export(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, string categoryCode, int advertiserCode, int brandCode, string productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa, string days, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            categoryCode = categoryCode != null ? categoryCode : "";
            productCode = productCode != null ? productCode : "";
            days = days != null ? days : "";
            DataTable dt = SPs.GetReportInternetPagedExport(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), mediaTypeCode, mediaCodes, sectorCode, subSectorCode, subSector2Code, categoryCode, advertiserCode, brandCode, productCode, prodVersionCode, agencyCode, sPrice, ePrice, fa, days).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }

        public int GetReportInternet_RowCountExport(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, int sectorCode, int subSectorCode, int subSector2Code, int categoryCode, int advertiserCode, int brandCode, int productCode, int prodVersionCode, int agencyCode, int sPrice, int ePrice, bool fa,string days, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }



        #endregion


        #region [Planning]

        //public  static DataTable GetReportPlanning_Paged(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        public static DataTable GetReportPlanning_Paged(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;
            mediaCodes = mediaCodes != null ? mediaCodes : "";
            DataTable dt = SPs.GetReportPlanningPaged(userID, page, maximumRows, sortColumn, sDate, eDate, mediaTypeCode, mediaCodes).GetDataSet().Tables[0];
            //int totalRecords = 0;
            //if (dt.Rows.Count > 0)
            //    totalRecords = Utility.ToInt(dt.Rows.Count);
            //totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);
            //e.Arguments.TotalRowCount = totalRecords;
            return dt;
        }

        public int GetReportPlanning_RowCount(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        public DataTable GetReportPlanning_Export(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;
            mediaCodes = mediaCodes != null ? mediaCodes : "";
            DataTable dt = SPs.GetReportPlanningExport(userID, page, maximumRows, sortColumn, sDate, eDate, mediaTypeCode, mediaCodes).GetDataSet().Tables[0];
            int totalRecords = 0;
            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);
            e.Arguments.TotalRowCount = totalRecords;
            return dt;
        }

        public int GetReportPlanning_RowCountExport(int userID, DateTime sDate, DateTime eDate, int mediaTypeCode, string mediaCodes, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        #endregion


        #region [Competition]
        public DataTable GetReportAll_Competition(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string brandName,int MediaTypeCode, bool searchIN, string brandNames, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            sectorName = sectorName != null ? sectorName : "";
            subSectorName = subSectorName != null ? subSectorName : "";
            categoryName = categoryName != null ? categoryName : "";
            brandName = brandName != null ? brandName : "";
            brandNames = brandNames != null ? brandNames : "";

            DataTable dt = SPs.GetReportAllCompetition(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), searchTV, searchRD, searchCB, searchPR, searchOD, mediaCodes, sectorName, subSectorName, categoryName, brandName, MediaTypeCode, searchIN, brandNames).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }
        public int GetReportCompetition_RowCount(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string brandName, int MediaTypeCode, bool searchIN, string brandNames, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        public DataTable GetReportAll_CompetitionGraph(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string brandName, int MediaTypeCode, bool searchIN, string brandNames, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            sectorName = sectorName != null ? sectorName : "";
            subSectorName = subSectorName != null ? subSectorName : "";
            categoryName = categoryName != null ? categoryName : "";
            brandName = brandName != null ? brandName : "";
            brandNames = brandNames != null ? brandNames : "";

            DataTable dt = SPs.GetReportAllCompetitionGraph(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), searchTV, searchRD, searchCB, searchPR, searchOD, mediaCodes, sectorName, subSectorName, categoryName, brandName, MediaTypeCode, searchIN, brandNames).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }
        public int GetReportCompetition_RowCountGraph(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string brandName, int MediaTypeCode, bool searchIN, string brandNames, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        public DataTable GetReportAll_Insertions(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string brandName, int MediaTypeCode, bool searchIN, string brandNames, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            sectorName = sectorName != null ? sectorName : "";
            subSectorName = subSectorName != null ? subSectorName : "";
            categoryName = categoryName != null ? categoryName : "";
            brandName = brandName != null ? brandName : "";
            brandNames = brandNames != null ? brandNames : "";

            DataTable dt = SPs.GetReportAllInsertions(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), searchTV, searchRD, searchCB, searchPR, searchOD, mediaCodes, sectorName, subSectorName, categoryName, brandName, MediaTypeCode, searchIN, brandNames).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }
        public int GetReportInsertions_RowCount(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string brandName, int MediaTypeCode, bool searchIN, string brandNames, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }


        public DataTable GetReportAll_InsertionsGraph(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string brandName, int MediaTypeCode, bool searchIN, string brandNames, ObjectDataSourceSelectingEventArgs e, string sortColumn, int maximumRows, int startRowIndex)
        {
            int page = startRowIndex + 1 > maximumRows ? ((startRowIndex / maximumRows) + 1) : 1;

            mediaCodes = mediaCodes != null ? mediaCodes : "";
            sectorName = sectorName != null ? sectorName : "";
            subSectorName = subSectorName != null ? subSectorName : "";
            categoryName = categoryName != null ? categoryName : "";
            brandName = brandName != null ? brandName : "";
            brandNames = brandNames != null ? brandNames : "";

            DataTable dt = SPs.GetReportAllInsertionsGraph(userID, page, maximumRows, sortColumn, sDate, eDate.AddDays(0), searchTV, searchRD, searchCB, searchPR, searchOD, mediaCodes, sectorName, subSectorName, categoryName, brandName, MediaTypeCode, searchIN, brandNames).GetDataSet().Tables[0];


            int totalRecords = 0;

            if (dt.Rows.Count > 0)
                totalRecords = Utility.ToInt(dt.Rows[0]["TotalRecords"]);

            e.Arguments.TotalRowCount = totalRecords;

            return dt;
        }
        public int GetReportInsertions_RowCountGraph(int userID, DateTime sDate, DateTime eDate, bool searchTV, bool searchRD, bool searchCB, bool searchPR, bool searchOD, string mediaCodes, string sectorName, string subSectorName, string categoryName, string brandName, int MediaTypeCode, bool searchIN, string brandNames, ObjectDataSourceSelectingEventArgs e)
        {
            return e.Arguments.TotalRowCount;
        }

        #endregion
    }

}